<template>
  <div>
    <template>
      <Card style="width:850px;margin: auto;">
        <Form :model="formLeft" label-position="left" :rules="validateLibForm" :label-width="100" style="width: 300px;margin: auto;">

          <FormItem label="工艺代码:" prop="code">
            <Input v-model="formLeft.code" :maxlength="10"></Input>
          </FormItem>

          <FormItem label="工艺名称:" prop="name">
            <Input v-model="formLeft.name" :maxlength="10"></Input>
          </FormItem>

          <row type="flex" justify="center">
            <i-col span="30">
              <Button type="primary" @click="ProcessInsert">添加</Button>
              <Button type="success" style="margin-left: 160px" @click="back">返回</Button>
            </i-col>
          </row>

        </Form>
      </Card>
    </template>
  </div>
</template>

<script>
  import {ProcessInsert} from "../../../api/data"

  export default {
    data() {
      return {
        formLeft: {
          code: '',
          name: ''
        },
        validateLibForm: {
          code: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
          name: [
            {required: true, message: '请输入', trigger: 'blur'}
          ],
        }
      }
    },
    mounted() {

    },
    methods: {
      ProcessInsert() {
        if (this.formLeft.code !== null && this.formLeft.code !== "") {
          if (this.formLeft.name !== null && this.formLeft.name !== "") {
            ProcessInsert(this.formLeft).then(res => {
              this.$Message.success("添加成功");
              this.$router.go(-1)
            })
          } else {
            this.$Message.error("工艺名称不能为空");
          }
        } else {
          this.$Message.error("工艺代码不能为空");
        }
      },
      back() {
        this.$router.go(-1);
      },

    }
  }
</script>

